package com.liuxin.zhiyuan.shujuzhongxin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liuxin.zhiyuan.shujuzhongxin.domain.dto.XueYuanListDTO;
import com.liuxin.zhiyuan.shujuzhongxin.mapper.XueyuanInfoMapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuxin.common.utils.PageUtils;
import com.liuxin.common.utils.Query;

import com.liuxin.zhiyuan.shujuzhongxin.domain.po.XueyuanInfoEntity;
import com.liuxin.zhiyuan.shujuzhongxin.service.XueyuanInfoService;


@Service
public class XueyuanInfoServiceImpl extends ServiceImpl<XueyuanInfoMapper, XueyuanInfoEntity> implements XueyuanInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String studentName = (String) params.get("studentName");
        String phone = (String) params.get("phone");
        IPage<XueYuanListDTO> page = new Query<XueYuanListDTO>().getPage(params);
        IPage<XueYuanListDTO> resultPage = this.baseMapper.selectXueyuanInfoPage(page, studentName,phone);
        return new PageUtils(resultPage);
    }
    @Override
    public boolean isPhoneExists(String phone, Integer excludeId) {
        QueryWrapper<XueyuanInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        // 如果是更新操作，排除当前记录
        if (excludeId != null) {
            queryWrapper.ne("id", excludeId);
        }
        return this.count(queryWrapper) > 0;
    }

}